#!/usr/bin/env python3


def plus_join(str_arr):
    s = str_arr[0]
    l = len(str_arr)
    for i in range(1, l):
        if str_arr[i][0] == '-':
            s += str_arr[i]
        else:
            s += '+' + str_arr[i]
    return s

A = {0: 3, 5: 6, 7: 10, 20: 6}

B = {0: -15, 3: 7, 5: -6, 8: -10, 20: 12, 25: 17}

C = B.copy()

for i in A:
    if i in B:
        C[i] += A[i]
    else:
        C[i] = A[i]

value_zero_keys = [i for i in C if C[i] == 0]
for i in value_zero_keys:
    del C[i]

c = []
for i in sorted(C, reverse=True):
    if i == 0:
        s = str(C[i])
    else:
        s = '{0}*x^{1}'.format(C[i], i)

    c.append(s)

print(plus_join(c))
